package com.hollycrm.unicom.sheet.business.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.hollycrm.springframework.web.struts.DispatchActionSupport;
import com.hollycrm.unicom.sheet.BeanResource;
import com.hollycrm.unicom.sheet.Constants;
import com.hollycrm.unicom.sheet.business.BusinessSupportManager;

/**
 * ListDealSheetAction
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author Tian Kai
 * @version 1.0
 */
public class ListDealSheetAction
    extends DispatchActionSupport {
    /**
     * execMainSheet
     *
     * @param mapping ActionMapping
     * @param actionForm ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward execMainSheet(ActionMapping mapping,
                                     ActionForm actionForm,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
        Exception {
        String mainSheetFlowNO = request.getParameter("sheetFlowNO");
        String archive = request.getParameter("archive");
        BusinessSupportManager bsm = getBusinessSupportManager(archive);
        List dealSheets = bsm.listDealSheets(mainSheetFlowNO);
        request.setAttribute("dealSheets", dealSheets);
        return mapping.findForward("success");
    }

    /**
     * execDealSheet
     *
     * @param mapping ActionMapping
     * @param actionForm ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward execDealSheet(ActionMapping mapping,
                                     ActionForm actionForm,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
        Exception {
        String sheetFlowNO = request.getParameter("sheetFlowNO");
        String archive = request.getParameter("archive");
        BusinessSupportManager bsm = getBusinessSupportManager(archive);
        List dealSheets = bsm.listDealSheets(sheetFlowNO, false);
        request.setAttribute("dealSheets", dealSheets);
        return mapping.findForward("success");
    }

    /**
     * getBusinessSupportManager
     *
     * @param archive String
     * @return BusinessSupportManager
     */
    private BusinessSupportManager getBusinessSupportManager(String archive) {
        if (Constants.TRUE.equals(archive))
            return (BusinessSupportManager) getBean(BeanResource.
                ARCHIVEBUSINESSSUPPORT_MANAGER);
        else
            return (BusinessSupportManager) getBean(BeanResource.
                BUSINESSSUPPORT_MANAGER);
    }

}
